package com.baidumap.administrator.happystudy.ui;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.baidumap.administrator.happystudy.base.JsonTools;
import com.baidumap.administrator.happystudy.base.Utils;
import com.baidumap.administrator.happystudy.R;
import com.baidumap.administrator.happystudy.adapter.SupermarketOrderAdapter;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SupermarketOrderDetailsActivity extends Activity {


    public ImageLoader loader;
    @Bind(R.id.goback)
    LinearLayout goback;
    @Bind(R.id.confirm_btn)
    Button confirmBtn;
    private ListView mListView;
    private ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    private SupermarketOrderAdapter mAdapter;
    private static int pageNo = 1;
    private ArrayList<Map<String, Object>> arrayList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_supermarket_order_details);
        ButterKnife.bind(this);
        iniListView();
    }

    private void iniListView() {

        // LoadImage初始化
        loader = ImageLoader.getInstance();
        pageNo = 1;
        mListView = (ListView) findViewById(R.id.list);
        mAdapter = new SupermarketOrderAdapter(SupermarketOrderDetailsActivity.this, loader);
        new MyTask().execute("", "" + pageNo);// 线程加载json数据
    }

    @OnClick({R.id.goback, R.id.confirm_btn})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.goback:
                finish();
                break;
            case R.id.confirm_btn:
                break;
        }
    }

    class MyTask extends
            AsyncTask<String, Void, ArrayList<Map<String, Object>>> {

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

        }

        @Override
        protected ArrayList<Map<String, Object>> doInBackground(
                String... params) {

            ArrayList<Map<String, Object>> mList = null;
            mList = (ArrayList<Map<String, Object>>) JsonTools.listKeyMaps(
                    "list", Utils.HOUSE_JSON);
            return mList;
        }

        protected void onPostExecute(ArrayList<Map<String, Object>> result) {
            // TODO Auto-generated method stub

            list.addAll(result);//

            mAdapter.bindData(list);
            if (pageNo == 1) {

                mListView.setAdapter(mAdapter);
            }
            pageNo++;
            mAdapter.notifyDataSetChanged();
            super.onPostExecute(result);

        }
    }
}
